package com.thz.houserental.infrastructure.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.thz.houserental.infrastructure.table.LogRecord;
import com.thz.houserental.infrastructure.web.dto.LogPageDto;
import com.thz.houserental.infrastructure.web.service.LogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/log")
@Tag(name = "日志管理")
public class LogController {
    private LogService logService;

    public LogController(LogService logService) {
        this.logService = logService;
    }

    @PostMapping("/list")
    @Operation(summary = "根据操作者名条件查询")
    public List<LogRecord> GetAllLoginInfo(@RequestBody LogPageDto logPageDto) {
        IPage<LogRecord> page = null;
        if (StringUtils.isEmpty(logPageDto.getOperator())) {
            page = logService.QueryAllLog(logPageDto.getPageNo(), logPageDto.getPageSize());
        } else {
            page = logService.QueryAllLogByOpUser(logPageDto);
        }
        return page.getRecords();
    }
}
